// Example usage of the request utility

// Import the request methods
import { get, post, put, del, patch } from './request';

// Example interface for type safety
interface User {
  id: number;
  name: string;
  email: string;
}

// Example usage of GET request
export const fetchUsers = async (): Promise<User[]> => {
  try {
    const users = await get<User[]>('/users');
    return users;
  } catch (error) {
    console.error('Failed to fetch users:', error);
    throw error;
  }
};

// Example usage of POST request
export const createUser = async (userData: Omit<User, 'id'>): Promise<User> => {
  try {
    const newUser = await post<User>('/users', userData);
    return newUser;
  } catch (error) {
    console.error('Failed to create user:', error);
    throw error;
  }
};

// Example usage of PUT request
export const updateUser = async (id: number, userData: Partial<User>): Promise<User> => {
  try {
    const updatedUser = await put<User>(`/users/${id}`, userData);
    return updatedUser;
  } catch (error) {
    console.error('Failed to update user:', error);
    throw error;
  }
};

// Example usage of DELETE request
export const deleteUser = async (id: number): Promise<void> => {
  try {
    await del<void>(`/users/${id}`);
  } catch (error) {
    console.error('Failed to delete user:', error);
    throw error;
  }
};

// Example usage of PATCH request
export const partialUpdateUser = async (id: number, userData: Partial<User>): Promise<User> => {
  try {
    const updatedUser = await patch<User>(`/users/${id}`, userData);
    return updatedUser;
  } catch (error) {
    console.error('Failed to partially update user:', error);
    throw error;
  }
};